package conf

import (
	"log"

	_ "com.zkh/agent/coap/objs"
	"github.com/spf13/viper"
)

type Config struct {
	CoapPort        int    `json:"coapPort"` // 默认 5683
	HttpPort        int    `json:"httpPort"` // 默认 8789
	DeviceCloudHost string `json:"deviceCloudHost"`
}

var (
	conf *Config
)

func init() {
	log.Printf("init config")
	conf = &Config{}
	vjson := viper.New()
	vjson.SetConfigName("config")
	vjson.SetConfigType("json")
	vjson.AddConfigPath("data/")
	if err := vjson.ReadInConfig(); err != nil {
		log.Fatalf("read config error: %v", err)
		return
	}
	vjson.SetDefault("coapPort", 8780)
	vjson.SetDefault("httpPort", 8789)
	vjson.Unmarshal(conf)

}

func GetCoapPort() int {
	return conf.CoapPort
}
func GetHttpPort() int {
	return conf.HttpPort
}

func GetDeviceCloudHost() string {
	return conf.DeviceCloudHost
}
